﻿using System;
using System.Collections.Generic;
using Tao.OpenGl;
using PacMan3D.Utils;
using Tao.FreeGlut;
using PacMan3D.IO;

namespace PacMan3D.Objects
{
    public class Light : IRenderable
    {
        private Maze Maze;

        // cor ambiente
        private float[] Ambient = { 0.4f, 0.4f, 0.4f, 1.0f };
        private float[] Difuse = { 0.7f, 0.7f, 0.7f, 1.0f };
        private float[] Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
        private float[] AmbientModel = { 0.4f, 0.4f, 0.4f, 1.0f };
        private float[] Position = new float[4];

        public Light(Maze maze)
        {
            this.Maze = maze;

            this.Position[0] = this.Maze.Platform.GetCentralPoint().X;
            this.Position[1] = 20.0f;
            this.Position[2] = this.Maze.Platform.GetCentralPoint().Z;
            this.Position[3] = 1.0f;

            // definição do modelo de iluminação
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, this.Ambient);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, this.Difuse);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, this.Specular);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_LIGHT_MODEL_AMBIENT, this.Ambient);

            //habilitação da luz em GL_LIGHT0
            Gl.glEnable(Gl.GL_LIGHT0);
        }

        // RGBAColor color = new RGBAColor(StandardColors.Green, 1.0f);
        public override void DrawObject()
        {
            Gl.glPushMatrix();
            // definição do posicionamento da luz
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, this.Position);
            Gl.glPopMatrix();

            /*
            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glPushMatrix();
                Gl.glTranslatef(this.Position[0], this.Position[1]-5, this.Position[2]);
                Gl.glColor4f(color.Red, color.Green, color.Blue, color.Alpha);
                Glut.glutSolidSphere(0.5, 12, 12);
            Gl.glPopMatrix();
            Gl.glDisable(Gl.GL_LIGHTING);
            */
        }

        public float[] GetPosition()
        {
            return this.Position;
        }
    }
}
